const express = require('express');
const {singers} = require('./data/singers.json')
// JSON文件里数据可以不用导出，直接引入就可以使用
const app = express();
app.get('/signer/:id.html', (req, res) => {
    let {id} = req.params;
    let singer = singers.find(item => item.id == id);
    console.log(singer)
    if(!singer) res.send('404 not found')
    res.send(`<!DOCTYPE html>
                <html lang="en">
                <head>
                    <meta charset="UTF-8">
                    <meta name="viewport" content="width=device-width, initial-scale=1.0">
                    <title>Document</title>
                </head>
                <body>
                    <h1>${singer.singer_name}</h1>
                    <img src="${singer.singer_pic}" alt="">
                </body>
                </html>`
            )
    
})
app.listen(3000,() => { console.log('服务器启动了') })